package com.uuah.server.endpoint;

import java.util.Map;

import com.uuah.server.api.IUuahContext;
import com.uuah.server.api.IUuahEvent;
import com.uuah.server.api.IUuahMessage;
import com.uuah.server.api.endpoint.IEndpointURI;
import com.uuah.server.api.endpoint.IUuahEndpoint;
import com.uuah.server.api.transformer.IBaseTransformer;
import com.uuah.server.api.transport.IConnector;
import com.uuah.server.api.transport.retry.RetryPolicyTemplate;
import com.uuah.server.exception.transport.DispatchException;

/**
 *
 * TODO comment ...
 *
 * <p>
 * update record:updator，update time，update content and version
 * </p>
 *
 * @author <a href="jonny_quan@hotmail.com">jonny</a>
 * @date 2009 2009-3-27 下午01:37:15
 * @version 1.0.0
 */
public class RequestEndpoint extends AbstractEndpoint implements IUuahEndpoint {

	private static final long serialVersionUID = -4752772777414636142L;

	public RequestEndpoint(IConnector connector, IEndpointURI endpointUri,
			IBaseTransformer requestTransformer,
			IBaseTransformer responseTransformer, String name, Map properties,
			boolean synchronous, boolean ipFilter, String initialState,
			String endpointEncoding, String endpointBuilderName,
			IUuahContext uuahContext, RetryPolicyTemplate retryPolicyTemplate) {
		super(connector, endpointUri, requestTransformer, responseTransformer,
				name, properties, synchronous, ipFilter, initialState,
				endpointEncoding, endpointBuilderName, uuahContext,
				retryPolicyTemplate);
	}

	public void dispatch(IUuahEvent event) throws DispatchException {
		if (getConnector() != null) {
			getConnector().dispatch(this, event);
		} else {
			throw new IllegalStateException("The connector on the endpoint: "
					+ toString() + " is null. ");
		}
	}

	public IUuahMessage send(IUuahEvent event) throws DispatchException {
		if (getConnector() != null) {
			return getConnector().send(this, event);
		} else {
			throw new IllegalStateException("The connector on the endpoint: "
					+ toString() + " is null.");
		}
	}
}
